package variable;

/**
 * An encapsulation over a variable that allows regular set and get operation,
 * the get operation will only return the value of the variable the first
 * time it is called, subsequent calls will return null (unless the set
 * method is called).
 * 
 * @author g1wshimu
 */
public class RetrieveOnce<T> {
    
    private T data;
    
    public RetrieveOnce() {
    }
    
    public RetrieveOnce(T data) {
        this.data = data;
    }
    
    protected void action() {        
    }
    
    public T get() {
        T returnVal = data;
        if (data == null) {
            action();
        } else {
            data = null;
        }
        
        return returnVal;
    }
    
    public void set(T data) {
        this.data = data;
    }
}
